const mock = require('mockjs')
const random = mock.Random
const getList =require('./data/getQuestionsList')
const getComponentList = require('./data/getComponentList')

const list = [
  {
    id: '1',
    title: '你好，请问有什么可以帮助您？',
    isPublished: true,
    isStar: true,
    answerCount: 10,
    createdAt: '2021-01-01 12:00:00',
    isDelected: false
  },
  {
    id: '2',
    title: '今天天气不错，有什么活动吗？',
    isPublished: true,
    isStar: false,
    answerCount: 15,
    createdAt: ' 2021-01-05 12:00:00',
    isDelected: false
  },
  {
    id: '3',
    title: '请问有什么关于前端的面试题吗？',
    isPublished: true,
    isStar: true,
    answerCount: 20,
    createdAt: '2021-01-08 12:00:00',
    isDelected: false
  },
  {
    id: '4',
    title: '请问有什么关于后端的面试题吗？',
    isPublished: true,
    isStar: false,
    answerCount: 12,
    createdAt: '2021-01-10 12:00:00',
    isDelected: false
  },
  {
    id: '5',
    title: '请问有什么关于测试的面试题吗？',
    isPublished: true,
    isStar: true,
    answerCount: 18,
    createdAt: '2021-01-12 12:00:00',
    isDelected: false
  },
  {
    id: '6',
    title: '请问有什么关于数据库的面试题吗？',
    isPublished: true,
    isStar: false,
    answerCount: 16,
    createdAt: '2021-01-15 12:00:00',
    isDelected: false
  },
  {
    id: '7',
    title: '请问有什么关于计算机网络的面试题吗？',
    isPublished: true,
    isStar: true,
    answerCount: 14,
    createdAt: '2021-01-18 12:00:00',
    isDelected: false
  },
  {
    id: '8',
    title: '请问有什么关于操作系统的面试题吗？',
    isPublished: true,
    isStar: false,
    answerCount: 11,
    createdAt: '2021-01-20 12:00:00',
    isDelected: false
  },
  {
    id: '9',
    title: '请问有什么关于计算机组成原理的面试题吗？',
    isPublished: true,
    isStar: true,
    answerCount: 13,
    createdAt: '2021-01-22 12:00:00',
    isDelected: false
  },
 
]






module.exports = [
  //获取问卷列表
  {
    url: '/question',
    method: 'get',
    response: (ctx) => {
      const {url} = ctx
       console.log(ctx.query)
      const isStar = url.includes('isStar=true')
      const isDeleted = url.includes('isDeleted=true')
      const keyword =ctx.query.keyword
      const pageSize = parseInt(ctx.query.pageSize)

      return {
        errno: 0,
        data:{
          list:getList({len:pageSize,isStar,isDeleted,keyword}),
          total:100
        },
        
      }
    }
  },
  // 获取某个问卷
  {
    url: '/question/:id',
    method: 'get',
    response: () => {
      return {
        errno: 0,
        data:{
          id: random.id(),
          name: random.name(),
          title: random.ctitle(),
          desc:"这是一份测试问卷",
          js:"js",
          css:"css",
          isPublished:true,
          isDelected:false,
          componentList: getComponentList()
        }
      }
    }
  },
  //更新问卷信息
  {
    url: '/question/:id',
    method:'put',
    response:(ctx)=>{
      return {
        errno:0,
      }
    }
  },
  //批量彻底删除问卷
  {
    url: '/question',
    method: 'delete',
    response: (ctx) => {
      //ids = ctx.query.ids
      return {
        errno: 0,
        data: {
          message: '批量删除成功'
        }
      }
    }
  },
]